package com.superhelper.task.job.order;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.superhelper.common.domain.AuserShop;
import com.superhelper.common.domain.TakeOutOrder;
import com.superhelper.common.domain.baidu.BdPushEntity;
import com.superhelper.common.mapper.TakeOutOrderMapper;
import com.superhelper.common.service.AliMQProducerService;
import com.superhelper.common.service.BaiduService;
import com.superhelper.task.job.ShopCache;

public class BdCancelOrderJob implements SimpleJob {
    private static final Logger log = LoggerFactory.getLogger(BdCancelOrderJob.class);
    @Autowired
    private TakeOutOrderMapper orderMapper;
    @Autowired
    private AliMQProducerService producer;

    @Autowired
    private BaiduService bdService;
    @Autowired
    protected ShopCache shopCache;

    @Override
    public void execute(ShardingContext shardingContext) {
        List<TakeOutOrder> orders = orderMapper.getUnProcessOrder("bd", 10);
        for (TakeOutOrder order : orders) {
            AuserShop shop = shopCache.getShop(order.getShopId(), AuserShop.SHOP_BAIDU);
            if (shop == null) {
                continue;
            }
            BdPushEntity entity = bdService.statusPush(shop.getSource(), order.getPlfOrderId(), "10", "1", "超时取消");
            producer.sendBdOrder(entity);
            log.info("cancel order:{}", order.getPlfOrderId());
        }
    }
}
